package com.heima.user.feign;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.api.R;
import com.heima.feign.user.IUserClient;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.user.pojos.ApUser;
import com.heima.user.service.ApUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Slf4j
@RestController
public class UserClient implements IUserClient {

    @Autowired
    private ApUserService apUserService;

    /**
     * 查询apUser的详细信息，返回对象
     * @param apUser
     * @return
     */
    @Override
    @PostMapping("/api/v1/user/get")
    public ResponseResult selectApUser(@RequestBody ApUser apUser) {
        if(apUser!=null){
            ApUser user = apUserService.getById(apUser.getId());
            return ResponseResult.okResult(user);
        }
        else {
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
    }

    @GetMapping("/api/v1/user/{id}")
    public ApUser findUserById(@PathVariable("id") Integer id) {
        return apUserService.getById(id);
    }
}